home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Programming / AmigaTalk / general / Form.st < prev    next >
Text File  |  2000-02-14  |  3KB  |  137 lines

  1. Class Form :Object
  2. ! text !
  3. [
  4.    new
  5.      text <- Array new: 0
  6. |
  7.    clipFrom: upperLeft to: lowerRight 
  8.      ! newForm newRow rsize left top rText !
  9.  
  10.      left    <- upperLeft  y - 1.  " left hand side"
  11.      top     <- upperLeft  x - 1.
  12.      rsize   <- lowerRight y - left.
  13.      newForm <- Form new.
  14.  
  15.      (upperLeft x to: lowerRight x) 
  16.         do: [:i |
  17.               newRow <- String new: rsize.
  18.               rText  <- self   row: i.
  19.  
  20.               (1 to: rsize) 
  21.                  do: [:j |
  22.                        newRow at: j
  23.                              put: (rText at: (left + j)
  24.                         ifAbsent: [$ ])
  25.                      ].
  26.  
  27.               newForm row: (i - top) put: newRow
  28.             ].
  29.       ^ newForm
  30. |
  31.    columns
  32.       ^ text inject: 0 into: [:x :y | x max: y size ]
  33. |
  34.    display
  35.       smalltalk clearScreen.  "If implemented!"
  36.       self printAt: 1 @ 1.
  37.       '  ' printAt: 20 @ 0
  38. |
  39.    eraseAt: aPoint   ! location !
  40.       location <- aPoint copy.
  41.       text do: [:x | (String new: (x size)) printAt: location.
  42.                      location x: (location x + 1) ]
  43. |
  44.    extent
  45.       ^ self rows @ self columns
  46. |
  47.    first
  48.       ^ text first
  49. |
  50.    next
  51.       ^ text next
  52. |
  53.    overLayForm: sourceForm at: startingPoint 
  54.    ! newRowNum rowText left rowSize !
  55.  
  56.       newRowNum <- startingPoint x.
  57.       left      <- startingPoint y - 1.
  58.  
  59.       sourceForm do: [:sourceRow |
  60.  
  61.          rowText <- self row: newRowNum.
  62.          rowSize <- sourceRow size.
  63.          rowText <- rowText padTo: (left + rowSize).
  64.  
  65.          (1 to: rowSize) do: [:i |
  66.             ((sourceRow at: i) ~= $ )
  67.             ifTrue: [ rowText at: (left + i) 
  68.                   put: (sourceRow at: i)]].
  69.  
  70.              self row: newRowNum put: rowText.
  71.          newRowNum <- newRowNum + 1]
  72. |
  73.    placeForm: sourceForm at: startingPoint 
  74.    ! newRowNum rowText left rowSize !
  75.  
  76.       newRowNum <- startingPoint x.
  77.       left      <- startingPoint y - 1.
  78.  
  79.       sourceForm do: [:sourceRow |
  80.          rowText <- self row: newRowNum.
  81.          rowSize <- sourceRow size.
  82.  
  83.          rowText <- rowText padTo: (left + rowSize).
  84.          (1 to: rowSize) do: [:i |
  85.             rowText at: (left + i) 
  86.                put: (sourceRow at: i)].
  87.  
  88.          self row: newRowNum put: rowText.
  89.          newRowNum <- newRowNum + 1]
  90. |
  91.    reversed      ! newForm columns newRow !
  92.       columns <- self columns.
  93.       newForm <- Form new.
  94.  
  95.       (1 to: self rows) do: [:i |
  96.          newRow <- text at: i.
  97.          newRow <- newRow , 
  98.             (String new: (columns - newRow size)).
  99.          newForm row: i put: newRow reversed ].
  100.  
  101.       ^ newForm
  102. |
  103.    rotated    ! newForm rows newRow !
  104.       rows <- self rows.
  105.       newForm <- Form new.
  106.  
  107.       (1 to: self columns) do: [:i |
  108.          newRow <- String new: rows.
  109.  
  110.          (1 to: rows) do: [:j |
  111.             newRow at: ((rows - j) + 1)
  112.                put: ((text at: j)
  113.                   at: i ifAbsent: [$ ])].
  114.  
  115.          newForm row: i put: newRow ].
  116.  
  117.       ^ newForm
  118. |
  119.    row: index
  120.       ^ text at: index ifAbsent: ['']
  121. |
  122.    row: index put: aString
  123.       (index > text size)
  124.          ifTrue: [ [text size < index] whileTrue:
  125.                [text <- text grow: ''] ].
  126.  
  127.       text at: index put: aString
  128. |
  129.    rows
  130.       ^ text size
  131. |
  132.    printAt: aPoint       ! location !
  133.       location <- aPoint copy.
  134.       text do: [:x | x printAt: location.
  135.             location x: (location x + 1) ]
  136. ]
  137.